#include "myitem.h"
#include<QPixmap>
#include<QDebug>
#include"handler.h"
#include<QCursor>

MyItem::MyItem()
{
    this->setPixmap(QPixmap(":/bg/pic/BeatMouse_p9.jpg"));
    this->start=false;
    this->mouse=false;
}

void MyItem::setPic(QString path)
{
    this->setPixmap(QPixmap(path));  //用于切换路径->切换图片
}

void MyItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    this->setCursor(QCursor(QPixmap(":/bg/pic/BeatMouse_p3.png")));
    //每点击一次都会判断this->mouse的bool值。来处理相应的事件
    Handler *hand=Handler::getInstance();
    if(this->isStart())
    {
        //这里会发送一个自定义的信号emit beatMouse();
        //当hand中addScore函数被调用的时候会发出一个beatMouse()信号
        if(this->isMouse())
        {
            hand->addScore();
        }
        if(!this->isMouse())
        {
            hand->subtractScore();
        }
    }
}

void MyItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    this->setCursor(QCursor(QPixmap(":/bg/pic/BeatMouse_p2.png")));//打到了地鼠，锤子切换到敲击的图片
}

void MyItem::setMouse(bool mouse)
{
    this->mouse=mouse;
}

bool MyItem::isMouse()
{
    return this->mouse;
}

void MyItem::setStart(bool start)
{
    this->start=start;
}

bool MyItem::isStart()
{
    return this->start;
}
